package algorithm.math;

/**
 * leetcode : https://leetcode.com/problems/ugly-number/description/
 * Difficulty : Easy
 *
 * 给定正数，仅被 2 3 5 整除的数是 uglyNumber （1也是uglyNumber）
 * 思路：
 * 只要整除 2 3 5 以后，剩余的结果为1，那就是uglyNumber
 * @Author Antony
 * @Since 2018/7/18 16:17
 */
public class UglyNumber {

    public static void main(String[] args) {
        int num = 4;
        System.out.println(isUgly(num));
    }


    /**
     * beats 100.0% - 1ms
     */
    public static boolean isUgly(int num) {
        if(num == 0) return false;
        while(num%2 == 0) num = num/2;
        while(num%3 == 0) num = num/3;
        while(num%5 == 0) num = num/5;
        return num==1;
    }
}
